/**
 * View World Quadrant 1.
 *
 * Released under Apache License, Version 2.0.
 */

package bsp.eclair.simplelinechart.viewworld;

public class ViewWorldQuadrant1 extends ViewWorld
{
	/**
	 * Default constructor.
	 * Create with default world object coordinate values, namely 0 to 1.
	 * View object coordinate values are default, namely 0 to 100.
	 * Origin is at 0,0 of world object.
	 * Padding values are zero.
	 */
	public ViewWorldQuadrant1()
	{
		super(VIEWWORLD_QUARTANT_1);
	}
	
	/**
	 * Create with default world object coordinate values, namely 0 to 1.
	 * View object coordinate values are as provided.
	 * Origin is at 0,0 of world object.
	 * Padding values are zero.
	 * 
	 * @param viewStartX
	 * @param viewStartY
	 * @param viewEndX
	 * @param viewEndY
	 */
	public ViewWorldQuadrant1(int viewStartX, int viewStartY, int viewEndX, int viewEndY)
	{
		super(VIEWWORLD_QUARTANT_1, viewStartX, viewStartY, viewEndX, viewEndY);
	}
	
	/**
	 * Create with default view object coordinate values, namely 0 to 100.
	 * World object coordinate values are as provided.
	 * Origin is at 0,0 of world object.
	 * Padding values are zero.
	 * 
	 * @param worldStartX
	 * @param worldStartY
	 * @param worldEndX
	 * @param worldEndY
	 */
	public ViewWorldQuadrant1(float worldStartX, float worldStartY, float worldEndX, float worldEndY)
	{
		super(VIEWWORLD_QUARTANT_1, worldStartX, worldStartY, worldEndX, worldEndY);
	}
	
	/**
	 * Initialize object using coordinate values provided.
	 * Origin is at 0,0 of world object.
	 * Padding values are zero.
	 * 
	 * @param worldStartX
	 * @param worldStartY
	 * @param worldEndX
	 * @param worldEndY
	 * @param viewStartX
	 * @param viewStartY
	 * @param viewEndX
	 * @param viewEndY
	 */
	public ViewWorldQuadrant1(float worldStartX, float worldStartY, float worldEndX, float worldEndY, int viewStartX, int viewStartY, int viewEndX, int viewEndY)
	{
		super(VIEWWORLD_QUARTANT_1, worldStartX, worldStartY, worldEndX, worldEndY, viewStartX, viewStartY, viewEndX, viewEndY);
	}
	
	/**
	 * Initialize using values provided.
	 * Padding values are zero.
	 * 
	 * @param worldStartX
	 * @param worldStartY
	 * @param worldEndX
	 * @param worldEndY
	 * @param originX
	 * @param originY
	 * @param viewStartX
	 * @param viewStartY
	 * @param viewEndX
	 * @param viewEndY
	 */
	public ViewWorldQuadrant1(float worldStartX, float worldStartY, float worldEndX, float worldEndY, float originX, float originY, int viewStartX, int viewStartY, int viewEndX, int viewEndY)
	{
		super(VIEWWORLD_QUARTANT_1, worldStartX, worldStartY, worldEndX, worldEndY, originX, originY, viewStartX, viewStartY, viewEndX, viewEndY);
	}
	
	/**
	 * Initialize using values provided.
	 * 
	 * @param worldStartX
	 * @param worldStartY
	 * @param worldEndX
	 * @param worldEndY
	 * @param originX
	 * @param originY
	 * @param viewStartX
	 * @param viewStartY
	 * @param viewEndX
	 * @param viewEndY
	 * @param leftPadding
	 * @param topPadding
	 * @param rightPadding
	 * @param bottomPadding
	 */
	public ViewWorldQuadrant1(float worldStartX, float worldStartY, float worldEndX, float worldEndY, float originX, float originY, int viewStartX, int viewStartY, int viewEndX, int viewEndY, int leftPadding, int topPadding, int rightPadding, int bottomPadding)
	{
		super(VIEWWORLD_QUARTANT_1, worldStartX, worldStartY, worldEndX, worldEndY, originX, originY, viewStartX, viewStartY, viewEndX, viewEndY, leftPadding, topPadding, rightPadding, bottomPadding); 
	}
	
	@Override
	public int convertToViewX(double worldX)
	{
		int retVal = 0;

		worldX = mWorldXMax - (worldX * mWorldXMax);
		retVal = (int) (( (mViewXMax - mViewXMin) / (mWorldXMax - mWorldXMin) ) * (worldX  - mWorldXMin) + mViewXMin);
		
		return retVal;
	}
	
	/**
	 * Convert x coordinate value in world to view which is in quadrant 1 - x increasing left, y increasing up
	 * @param worldX
	 * @return
	 */
	@Override
	public int convertToViewY(double worldY)
	{
		int retVal = 0;

		worldY = mWorldYMax - (worldY * mWorldYMax);
		retVal = (int) (( (mViewYMax - mViewYMin) / (mWorldYMax - mWorldYMin) ) * (worldY  - mWorldYMin) + mViewYMin);
		
		return retVal;
	}

	/**
	 * Convert x and y coordinate value in world to view which is in quadrant 1 - x increasing left, y increasing up
	 * @param worldX
	 * @return
	 */
	@Override
	public Point2DInt convertToView(double worldX, double worldY)
	{
		Point2DInt retPt = new Point2DInt();
		
		retPt.mX = (int) (( (mViewXMax - mViewXMin) / (mWorldXMax - mWorldXMin) ) * (worldX  - mWorldXMin) + mViewXMin);
		worldY = mWorldYMax - (worldY * mWorldYMax);
		retPt.mY = (int) (( (mViewYMax - mViewYMin) / (mWorldYMax - mWorldYMin) ) * (worldY - mWorldYMin) + mViewYMin);
		
		return retPt;
	}
	
	/**
	 * Convert 2d point value in world to view which is in quadrant 1 - x increasing left, y increasing up
	 * @param worldX
	 * @return
	 */
	@Override
	public Point2DInt convertToView(Point2DFloat pt)
	{
		Point2DInt retPt = new Point2DInt();
		
		retPt.mX = (int) (( (mViewXMax - mViewXMin) / (mWorldXMax - mWorldXMin) ) * (pt.mX  - mWorldXMin) + mViewXMin);
		float temp = mWorldYMax - (pt.mY * mWorldYMax);
		retPt.mY = (int) (( (mViewYMax - mViewYMin) / (mWorldYMax - mWorldYMin) ) * (temp  - mWorldYMin) + mViewYMin);
		
		return retPt;
	}
	
	/**
	 * Convert rectangle value in world to view which is in quadrant 1 - x increasing left, y increasing up
	 * @param worldX
	 * @return
	 */
	@Override
	public RectInt convertToView(RectFloat world)
	{
		RectInt ret = new RectInt();
		
		ret.left = (int) (( (mViewXMax - mViewXMin) / (mWorldXMax - mWorldXMin) ) * (world.left  - mWorldXMin) + mViewXMin);
		float temp = mWorldYMax - (world.top * mWorldYMax);
		ret.top = (int) (( (mViewYMax - mViewYMin) / (mWorldYMax - mWorldYMin) ) * (temp - mWorldYMin) + mViewYMin);
		
		ret.right = (int) (( (mViewXMax - mViewXMin) / (mWorldXMax - mWorldXMin) ) * (world.right  - mWorldXMin) + mViewXMin);
		temp = mWorldYMax - (world.bottom * mWorldYMax);
		ret.bottom = (int) (( (mViewYMax - mViewYMin) / (mWorldYMax - mWorldYMin) ) * (temp - mWorldYMin) + mViewYMin);
		
		return ret;
	}
	
	/**
	 * Convert x coordinate value in view to world which is in quadrant 1 - x increasing left, y increasing up
	 * @param viewX
	 * @return
	 */
	@Override
	public float convertToWorldX(int viewX)
	{
		float retVal = 0;
		
		retVal = (( (mWorldXMax - mWorldXMin) / (mViewXMax - mViewXMin) ) * (viewX  - mViewXMin) + mWorldXMin);
		
		return retVal;
	}
	
	/**
	 * Convert y coordinate value in view to world which is in quadrant 1 - x increasing left, y increasing up
	 * @param viewX
	 * @return
	 */
	@Override
	public float convertToWorldY(int viewY)
	{
		float retVal = 0;
		
		retVal = (( (mWorldYMax - mWorldYMin) / (mViewYMax - mViewYMin) ) * (viewY  - mViewYMin) + mWorldYMin);
		
		return retVal;
	}
	
	/**
	 * Convert 2d point value in view to world which is in quadrant 1 - x increasing left, y increasing up
	 * @param viewX
	 * @return
	 */
	@Override
	public Point2DFloat convertToWorld(int viewX, int viewY)
	{
		Point2DFloat retPt = new Point2DFloat();
		
		retPt.mX = (( (mWorldXMax - mWorldXMin) / (mViewXMax - mViewXMin) ) * (viewX  - mViewXMin) + mWorldXMin);
		retPt.mY = (( (mWorldYMax - mWorldYMin) / (mViewYMax - mViewYMin) ) * (viewY  - mViewYMin) + mWorldYMin);
		
		return retPt;
	}
	
	/**
	 * Convert 2d coordinate value in view to world which is in quadrant 1 - x increasing left, y increasing up
	 * @param viewX
	 * @return
	 */
	@Override
	public Point2DFloat convertToWorld(Point2DInt pt)
	{
		Point2DFloat retPt = new Point2DFloat();
		
		retPt.mX = (( (mWorldXMax - mWorldXMin) / (mViewXMax - mViewXMin) ) * (pt.mX  - mViewXMin) + mWorldXMin);
		retPt.mY = (( (mWorldYMax - mWorldYMin) / (mViewYMax - mViewYMin) ) * (pt.mY  - mViewYMin) + mWorldYMin);
		
		return retPt;
	}
}

/* end */
